package qlsl.androiddesign.view.subview.activityview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.qlsl.androiddesign.kuaiwa.R;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import qlsl.androiddesign.activity.subactivity.CarActivity;
import qlsl.androiddesign.activity.subactivity.CarBuyActivity;
import qlsl.androiddesign.adapter.subadapter.CarBuyAdapter;
import qlsl.androiddesign.manager.ActivityManager;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * 买车页<br/>
 * 需要传入的键：<br/>
 * 传入的值类型： <br/>
 * 传入的值含义：<br/>
 * 是否必传 ：
 */
public class CarBuyView extends FunctionView<CarBuyActivity> {

	private ListView listView;

	public CarBuyView(CarBuyActivity activity) {
		super(activity);
		setContentView(R.layout.activity_car_buy);
	}

	protected void initView(View view) {
		Activity activity = ActivityManager.getInstance().previousActivity();
		if (activity.getClass().getSimpleName().contains("SellVehicleActivity")) {
			setTitle("分类");
		} else {
			setTitle("买车");
		}
		listView = findViewById(R.id.listView);
		listView.setEmptyView(findViewById(R.id.tv_empty));
	}

	protected void initData() {
		setListViewData();
	}

	protected void initListener() {

	}

	public <T> void showData(T... t) {

	}

	public <T> void showNoData(T... t) {

	}

	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.list_item:
			doClickListItem(view);
			break;
		}
	}

	private void doClickListItem(View view) {
		TextView tv_title = findViewById(R.id.tv_title);
		String title = tv_title.getText().toString();
		int position = listView.getPositionForView(view);
		if (title.equals("买车")) {
			Intent intent = new Intent(activity, CarActivity.class);
			intent.putExtra("position", position);
			startActivity(intent);
		} else {
			String[] texts = new String[] { "小挖", "小挖", "中挖", "中挖", "大挖" };
			String[] descs = new String[] { "6吨以下	", "6-9吨", "10-19吨", "20-29吨", "30吨以上" };
			Intent intent = new Intent();
			intent.putExtra("category", texts[position] + descs[position]);
			activity.setResult(0, intent);
			activity.finish();
		}
	}

	private void setListViewData() {
		Integer[] icons = new Integer[] { R.drawable.xiao1, R.drawable.xiao2, R.drawable.zhong1, R.drawable.zhong2,
				R.drawable.da1 };
		String[] texts = new String[] { "小挖", "小挖", "中挖", "中挖", "大挖" };
		String[] descs = new String[] { "6吨以下	", "6-9吨", "10-19吨", "20-29吨", "30吨以上" };
		List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
		for (int index = 0; index < texts.length; index++) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("icon", icons[index]);
			map.put("text", texts[index]);
			map.put("desc", descs[index]);
			list.add(map);
		}
		CarBuyAdapter adapter = new CarBuyAdapter(activity, list);
		listView.setAdapter(adapter);

	}

}
